<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>定位</title>
    <style>
        body{
            margin: 0px;
            padding: 0px;
            font-size: 18px;
            font-weight: bold;
        }
        .father{
            margin: 10px auto;
            width: 300px;
            height: 300px;
            padding: 10px;
            background: #ccc;
            border: 1px solid #000;
        }
        .box1,
        .box2,
        .box3,
        .box4{
            width: 100px;
            height: 50px;
            line-height: 50px;
            background: #ff0;
            border: 1px solid #000;
            margin: 10px 0px;
            text-align: center;
        }
        .box2{
            /* 相对定位    相对于大盒子定位*/
            position: relative;
            /* 和左边框距离 */
            left: 150px;
            /* 和上边框距离 */
            top: 100px;
            /* z-index值越大，盒子在层叠位置越居上 */
            z-index: 5;

        }
        .box3{
            /* 绝对定位   以窗口为参照物*/
            position: absolute;
            left: 200px;
            top: 150px;
        }
        .box4{
            /* 固定定位   固定在窗口的某一位置上*/
            position: fixed;
            left: 500px;
            top: 150px;
        }
    </style>
</head>
<body>
    <div class="father">
        <div class="box1">box1</div>
        <div class="box2">box2</div>
        <div class="box3">box3</div>
        <div class="box4">box4</div>

    </div>
</body>
</html>